/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.api.internal;

import net.sourceforge.perforce.api.IClientUserDelegate;
import net.sourceforge.perforce.api.IError;

import java.util.Map;

/**
 * Wrapper class for Perforce API ClientUser class.
 * 
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net>Boris
 *         Pruessmann</a>
 */
public final class ClientUser {

  /**
   * Used to store the native reference. <br>
   * DON'T TOUCH THE CONTENT OF THIS VARIABLE
   */
  @SuppressWarnings("unused")
  private int _nativeHandle;

  /**
   * Stores instance of IClientUserDelegate used as delegate of this ClientUser
   * object.
   */
  private IClientUserDelegate delegate;

  /**
   * Constructor for ClientUser.
   * 
   * @param delegate IClientUserDelegate to be used.
   */
  ClientUser(IClientUserDelegate delegate) {
    construct();
    this.delegate = delegate;
  }

  /** Destroys the native ClientUser. */
  public void dispose() {
    this.delegate = null;
    destruct();
  }

  /**
   * Delegates callback to IClientUserDelegate.inputData.
   * 
   * @param error to be filled in error case.
   * @return data used as input for '-i' commands.
   */
  public String inputData(IError error) {
    return delegate.inputData(error);
  }

  /**
   * Delegates callback to IClientUserDelegate.outputError.
   * 
   * @param errorString Error message provided by Perforce ClientApi API.
   */
  public void outputError(String errorString) {
    delegate.outputError(errorString);
  }

  /**
   * Delegates callback to IClientUserDelegate.outputInfo.
   * 
   * @param level level of info message.
   * @param infoString Info message provided by Perforce ClientApi API.
   */
  public void outputInfo(char level, String infoString) {
    delegate.outputInfo(level, infoString);
  }

  /**
   * Delegates callback to IClientUserDelegate.outputBinary.
   * 
   * @param data binary data.
   */
  public void outputBinary(byte[] data) {
    delegate.outputBinary(data);
  }

  /**
   * Delegates callback to IClientUserDelegate.outputText.
   * 
   * @param data text data.
   */
  public void outputText(byte[] data) {
    delegate.outputText(data);
  }

  /**
   * Delegates callback to IClientUserDelegate.outputStat.
   * 
   * @param data Map as result of commands like fstat.
   */
  public void outputStat(Map<String, ?> data) {
    delegate.outputStat(data);
  }

  /**
   * Delegates callback to IClientUserDelegate.handleError.
   * 
   * @param error Error data to be processed as a result of a failed operation.
   */
  public void handleError(IError error) {
    delegate.handleError(error);
  }

  /**
   * Delegates callback to IClientUserDelegate.message.
   * 
   * @param error Error data to be processed as a result of a failed operation.
   */
  public void message(IError error) {
    delegate.message(error);
  }

  /**
   * Delegates callback to IClientUserDelegate.resolve.
   * 
   * @param clientMerge ClientMerge used for resolved operation.
   */
  public void resolve(ClientMerge clientMerge) {
    // TODO:
    throw new UnsupportedOperationException();
  }

  /**
   * Delegates callback to IClientUserDelegate.prompt.
   * 
   * @param msg -
   * @param noEcho -
   * @param error -
   * @return user provided answer to prompt operation.
   */
  public String prompt(String msg, boolean noEcho, Error error) {
    // TODO:
    throw new UnsupportedOperationException();
  }

  /** Delegates callback to IClientUserDelegate.finished. */
  public void finished() {
    delegate.finished();
  }

  /** Creates the native ClientUser object. */
  private native void construct();

  /** Destroys the native ClientUser object. */
  private native void destruct();
}
